var gLoginUsername = "${loginUsername}"; // 获得当前登录人员的userName
var gDeptUid = '${request.getParameter("deptUid")}';

// @Bind #view.onReady
!function(self, arg) {
	var workCenter = view.id("dsWorkCenter");
	var device = view.id("dsDevice");
	
	workCenter.set("parameter", {
		deptUid : gDeptUid
	});
	device.set("parameter", gDeptUid);
	
	workCenter.flush();
	device.flush();
}

// @Bind #dpCriticalLevel.beforeExecute
!function(self, arg, dsTypesData) {
	dsTypesData.set("parameter", {
		typeName : "critical_level"
	});
	dsTypesData.flush();
}

// @Bind #dpCriticalLevel.onValueSelect
!function(self, arg, dsTypesData, dsWorkCenter) {
	var typesData = dsTypesData.getData("#");
	var workCenter = dsWorkCenter.getData("#");

	workCenter.set("criticalLevel", typesData.get("typeId"));

}

// @Bind #dpWorkType.beforeExecute
!function(self, arg, dsTypesData) {
	dsTypesData.set("parameter", {
		typeName : "optype"
	});
	dsTypesData.flush();
}

// @Bind #dpWorkType.onValueSelect
!function(self, arg, dsTypesData, dsWorkCenter) {
	var typesData = dsTypesData.getData("#");
	var workCenter = dsWorkCenter.getData("#");
	
	workCenter.set("workType", typesData.get("typeId"));

}

// @Bind #dpDispatchGrade.beforeExecute
!function(self, arg, dsTypesData) {
	dsTypesData.set("parameter", {
		typeName : "dispatchgrade"
	});
	dsTypesData.flush();

}

// @Bind #dpDispatchGrade.onValueSelect
!function(self, arg, dsTypesData, dsWorkCenter) {
	var typesData = dsTypesData.getData("#");
	var workCenter = dsWorkCenter.getData("#");

	workCenter.set("dispatchGrade", typesData.get("typeId"));

}

//@Bind #dgCalendar1.onDataRowClick
!function(self, arg, dsCalendar, dsWorkCenter) {
	var dropDown = dorado.widget.DropDown.findDropDown(self);

	var calendar = dsCalendar.getData("#");
	var workCenter = dsWorkCenter.getData("#");

	workCenter.set("defaultCalendarUid", calendar.get("calendarUid"));
	workCenter
			.set("defaultCalendar.calendarName", calendar.get("calendarName"));

	dropDown.close();
}

//@Bind #dgCalendar2.onDataRowClick
!function(self, arg, dsCalendar, dsDevice) {
	var dropDown = dorado.widget.DropDown.findDropDown(self);
	
	var calendar = dsCalendar.getData("#");
	var device = dsDevice.getData("#");
	
	device.set("defaultCalendarUid", calendar.get("calendarUid"));
	device.set("defaultCalendar.calendarName", 
			calendar.get("calendarName"));
	
	dropDown.close();
}

// @Bind #deptTree4WorkCenter.onDataRowClick
!function(self, arg, dsWorkCenter) {
	var dropDown = dorado.widget.DropDown.findDropDown(self);
	var node = self.get("currentNode");
	var workCenter = dsWorkCenter.getData("#");

	workCenter.set("deptUid", node.get("data").get("uuid"));
	workCenter.set("dept.deptName", node.get("data").get("deptName"));

	dropDown.close(node.get("data"));

}

// @Bind #deptTree4Device.onDataRowClick
!function(self, arg, dsDevice) {
	var dropDown = dorado.widget.DropDown.findDropDown(self);
	var node = self.get("currentNode");
	var device = dsDevice.getData("#");

	device.set("deptUid", node.get("data").get("uuid"));
	device.set("dept.deptName", node.get("data").get("deptName"));

	dropDown.close(node.get("data"));

}

//@Bind #dsDept.onReady
!function(self, arg) {
	var dsDept = view.id("dsDept");
	var user = view.id("dsUser").getData("#");
	
	dsDept.set("parameter", user.get("deptUid"));
}
